import { defineStore } from 'pinia'
import { store } from '/@/store'
import type { AxiosResponse } from 'axios'
import type { Res } from '/@/tool/Res'
import type { Param } from '/@/tool/Param'

import confService from '/@/api/cn/core/conf/confService'

import type { Conf } from '/@/model/cn/core/conf/eo/Conf'
import type { ConfQO } from '/@/model/cn/core/conf/qo/ConfQO'
import type { ConfVO } from '/@/model/cn/core/conf/vo/ConfVO'

interface ConfState {
}

export const useConfStore = defineStore({
  id: 'conf',
  state: (): ConfState => ({
  }),
  getters: {
  },
  actions: {
    save(param: Param<Conf>): Promise<Res<Conf>> {
      return new Promise<Res<Conf>>((resolve, reject) => {
        confService.save(param).then((res: AxiosResponse<Res<Conf>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    saveBatch(param: Param<Conf>): Promise<Res<Conf>> {
      return new Promise<Res<Conf>>((resolve, reject) => {
        confService.saveBatch(param).then((res: AxiosResponse<Res<Conf>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    update(param: Param<Conf>): Promise<Res<Conf>> {
      return new Promise<Res<Conf>>((resolve, reject) => {
        confService.update(param).then((res: AxiosResponse<Res<Conf>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    updateBatch(param: Param<Conf>): Promise<Res<Conf>> {
      return new Promise<Res<Conf>>((resolve, reject) => {
        confService.updateBatch(param).then((res: AxiosResponse<Res<Conf>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    remove(param: Param<Conf>): Promise<Res<Conf>> {
      return new Promise<Res<Conf>>((resolve, reject) => {
        confService.remove(param).then((res: AxiosResponse<Res<Conf>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    removeBatch(param: Param<Conf>): Promise<Res<Conf>> {
      return new Promise<Res<Conf>>((resolve, reject) => {
        confService.removeBatch(param).then((res: AxiosResponse<Res<Conf>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    count(param: Param<ConfQO>): Promise<Res<Conf>> {
      return new Promise<Res<Conf>>((resolve, reject) => {
        confService.count(param).then((res: AxiosResponse<Res<Conf>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    pk(param: Param<ConfQO>): Promise<Res<Conf>> {
      return new Promise<Res<Conf>>((resolve, reject) => {
        confService.pk(param).then((res: AxiosResponse<Res<Conf>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    query(param: Param<ConfQO>): Promise<Res<Conf>> {
      return new Promise<Res<Conf>>((resolve, reject) => {
        confService.query(param).then((res: AxiosResponse<Res<Conf>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    paging(param: Param<ConfQO>): Promise<Res<Conf>> {
      return new Promise<Res<Conf>>((resolve, reject) => {
        confService.paging(param).then((res: AxiosResponse<Res<Conf>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    countVo(param: Param<ConfQO>): Promise<Res<ConfVO>> {
      return new Promise<Res<ConfVO>>((resolve, reject) => {
        confService.countVo(param).then((res: AxiosResponse<Res<ConfVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    pkVo(param: Param<ConfQO>): Promise<Res<ConfVO>> {
      return new Promise<Res<ConfVO>>((resolve, reject) => {
        confService.pkVo(param).then((res: AxiosResponse<Res<ConfVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    queryVo(param: Param<ConfQO>): Promise<Res<ConfVO>> {
      return new Promise<Res<ConfVO>>((resolve, reject) => {
        confService.queryVo(param).then((res: AxiosResponse<Res<ConfVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
    pagingVo(param: Param<ConfQO>): Promise<Res<ConfVO>> {
      return new Promise<Res<ConfVO>>((resolve, reject) => {
        confService.pagingVo(param).then((res: AxiosResponse<Res<ConfVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
  },
})

export function useConfStoreWithout() {
  return useConfStore(store)
}
